/*
 * @ClassName VerifyCodeMapper
 * @Description 
 * @version 1.0
 * @Date 2024-06-17 15:33:37
 */
package com.taoge.biz.persistent.dao;

import com.taoge.biz.common.enums.SmsActionType;
import com.taoge.biz.persistent.entity.VerifyCode;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;

public interface VerifyCodeMapper {
    @Delete({
        "delete from `verify_code`",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into `verify_code` (user_id, mobile, ",
        "code, action_type, ",
        "`status`, fail_count, ",
        "expire_time)",
        "values (#{userId,jdbcType=BIGINT}, #{mobile,jdbcType=VARCHAR}, ",
        "#{code,jdbcType=VARCHAR}, #{actionType,jdbcType=VARCHAR}, ",
        "#{status,jdbcType=CHAR}, #{failCount,jdbcType=INTEGER}, ",
        "#{expireTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(VerifyCode record);

    int insertSelective(VerifyCode record);

    @Select({
        "select",
        "id, user_id, mobile, code, action_type, `status`, fail_count, expire_time",
        "from `verify_code`",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    VerifyCode selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(VerifyCode record);

    @Update({
        "update `verify_code`",
        "set user_id = #{userId,jdbcType=BIGINT},",
          "mobile = #{mobile,jdbcType=VARCHAR},",
          "code = #{code,jdbcType=VARCHAR},",
          "action_type = #{actionType,jdbcType=VARCHAR},",
          "`status` = #{status,jdbcType=CHAR},",
          "fail_count = #{failCount,jdbcType=INTEGER},",
          "expire_time = #{expireTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(VerifyCode record);

    List<VerifyCode> list(HashMap<String, ?> map);

    Long count(HashMap<String, ?> map);

    List<VerifyCode> selectByIds(List<?> list);

    /**
     * @title: selectValidCode
     * @description: 查询等待验证code
     * @date:   2024-07-01 10:35:23
     * @author: YaoSiCheng
     * @param:  userId
     * @param:  mobile
     * @param:  actionType
     * @return: VerifyCode
     */
    VerifyCode selectValidCode(@Param("userId") Long userId,@Param("mobile") String mobile,@Param("actionType") String actionType);

    /**
     * @title: updateExpireCode
     * @description: 修改验证码状态成失效
     * @date:   2024-07-01 11:23:39
     * @author: YaoSiCheng
     * @param:  userId
     * @param:  mobile
     * @param:  actionType
     * @return: int
     */
    int updateExpireCode(@Param("userId") Long userId,@Param("mobile") String mobile,@Param("actionType") String actionType);
}